<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<h2>登录</h2>
<form id="f1">
    Account:<input type="text" name="account"/><br>
    Password:<input type="password" name="password"/><br>
    <input type="button" value="登录"/>
</form>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
    $(function(){
        $(':button').on('click', function(){
            let params = $('#f1').serialize();
            $.ajax({
                url: 'auth',
                type: 'post',
                data: params,
                success: function(result){
                    if(result.code === 10000) {
                        alert(result.message);
                    } else if(result.code === 200){
                        let token = result.data;
                        //将token保存到本地存储
                        localStorage.setItem("token", token);
                        //跳转到首页
                        location.href = 'index.html';
                    }
                }
            });
        });
    })
</script>
</body>
</html>